package com.bawei.rk_01.Adapter

import android.graphics.Paint
import android.text.TextWatcher
import android.widget.ImageView
import android.widget.TextView
import com.bawei.base.utils.bean.Goods
import com.bawei.rk_01.R
import com.bawei.rk_01.Room.AppDBUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class GoodsAdapter : BaseQuickAdapter<Goods,BaseViewHolder>(R.layout.item_goods) {
    override fun convert(holder: BaseViewHolder, item: Goods) {
        GlideUtils.loadImage(context,item.image,holder.getView(R.id.goods_iamge))
        holder.setText(R.id.goods_name,item.storeName)
        holder.setText(R.id.goods_price,"￥"+item.price)
        holder.setText(R.id.goods_otprice,"￥"+item.otPrice)
        holder.setText(R.id.goods_sale,"已售${item.sales+item.ficti}件")
        //中划线
        val textWatcher = holder.getView<TextView>(R.id.goods_otprice)
        textWatcher.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG

        val query = AppDBUtils.getDB().liveDao().query(item.storeName)
        if (query==null){
            val live = holder.getView<ImageView>(R.id.live)
            live.setImageResource(R.drawable.baseline_favorite_border_24)
        }else{
            val live = holder.getView<ImageView>(R.id.live)
            live.setImageResource(R.drawable.baseline_favorite_24)
        }

    }
}